package cc.telecomdigital.tdstock.Http.Services;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Handler;
import cc.telecomdigital.tdstock.CommonDefn;
import cc.telecomdigital.tdstock.DateUtils;
import cc.telecomdigital.tdstock.ITDLApplication;
import cc.telecomdigital.tdstock.Framework.UniqueItem.DeviceInfo;
import cc.telecomdigital.tdstock.Framework.UniqueItem.TDStockLog;
import cc.telecomdigital.tdstock.Http.H_CODE;
import cc.telecomdigital.tdstock.Http.Services.H_HttpServiceRequest.H_UserClient_HttpRequest_Result;
import cc.telecomdigital.tdstock.Http.Services.H_HttpServiceRequest.IH_UserClient_HttpRequest_Report;
import cc.telecomdigital.tdstock.Http.Services.H_ILoginAuthRequest.H_ILoginAuthRequest_Result;
import cc.telecomdigital.tdstock.Http.Services.H_ILoginAuthRequest.IH_ILoginAuthRequest_Report;
import cc.telecomdigital.tdstock.Http.Tools.CommonTools.BMPPage;
import cc.telecomdigital.tdstock.Services.LS_ClientParamMemory;
import cc.telecomdigital.tdstock.Services.LS_UserClient.ILS_UserClient_Authentication_Report;
import cc.telecomdigital.tdstock.utils.BMPEntityBase;
import cc.telecomdigital.tdstock.utils.Futures;
import cc.telecomdigital.tdstock.utils.Fx;
import cc.telecomdigital.tdstock.utils.Index;
import cc.telecomdigital.tdstock.utils.Metal;
import cc.telecomdigital.tdstock.utils.Oil;
import cc.telecomdigital.tdstock.utils.Stock;
import cc.telecomdigital.tdstock.utils.Top20Stock;
import cc.telecomdigital.tdstock.utils.WorldFutures;
import cc.telecomdigital.tdstock.utils.WorldIndex;

/**
 * Http client request services tools
 * 
 * @author ouyangzhihui
 * 
 */
public class HttpAppInfo
{
	static private final String			LOG_TAG				= "HttpAppInfo";

	static private boolean				debugMode				= false;
	static private boolean				isInitialized			= false;
	static private Handler				msgHandler			= new Handler();
	static private Context				iContext				= null;
	static private String				deviceId				= null;
	static private String				activateCode			= null;
	// static final String default_acctNum = "";
	// static final String default_sessionId = "";

	static private Map<String, Boolean>	isCommunicatingMap		= new HashMap<String, Boolean>();
	static private boolean				isLSLogonCommunicating	= false;

	static private SharedPreferences		prefFile;

	static public void Init(Context actContext)
	{
		// Prevent multiple Initialization
		if (isInitialized == true)
			return;

		isInitialized = true;
		iContext = actContext;
		prefFile = iContext.getSharedPreferences(
				CommonDefn.SYSTEM_CURRENT_SETTING, Activity.MODE_PRIVATE);

		// Update to the bet Structure
		deviceId = DeviceInfo.GetDeviceID(iContext);

		isLSLogonCommunicating = false;
		isCommunicatingMap.clear();
	}

	static public String GetUserName()
	{
		if (iContext == null)
			return "";
		return ((ITDLApplication) iContext.getApplicationContext())
				.getUserName("");
	}

	static public String GetPassword()
	{
		if (iContext == null)
			return "";

		return ((ITDLApplication) iContext.getApplicationContext())
				.getPwd("");
	}

	static public boolean IsFreeTrial()
	{
		if (iContext == null)
			return false;

		return ((ITDLApplication) iContext.getApplicationContext())
				.isAuthComeFromActivationCode();
	}

	static public String GetActivateCode()
	{
		if (activateCode != null)
			return activateCode;

		activateCode = prefFile.getString(
				CommonDefn.PREFERENCE_TRIAL_ACTIVE_CODE, "");
		return activateCode;
	}

	/** Get the Identification for the device **/
	static public String GetDeviceID(Context iContext)
	{
		if (deviceId != null)
			return deviceId;

		deviceId = DeviceInfo.GetDeviceID(iContext);
		return deviceId;
	}

	static public String GetAccountNum()
	{
		if (iContext == null)
			return "";

		return ((ITDLApplication) iContext.getApplicationContext())
				.GetLSClient_AccountLogonName();
	}

	static public String GetSessionId()
	{
		if (iContext == null)
			return "";

		return ((ITDLApplication) iContext.getApplicationContext())
				.GetLSClient_SessionKey();
	}

	static final public int		PAGE_SIZE					= 20;
	static final private int		FETCH_DATETIME_LENGTH		= 19;
	static final private String	DEST_PARAM_DATETIME_FORMAT	= "%02d-%02d-%02d_%02d%02d%02d";
	static final private String	SOURCE_DATETIME_FORMAT		= "yyyy-MM-dd HH:mm:ss";
	static final private String	DEST_DATETIME_FORMAT		= "yyyy-MM-dd_HHmmss";
	static final private String	START_DATETIME_FORMAT		= "yyyy-MM-dd_010101";
	static final private Calendar	calendar					= Calendar.getInstance();

	static public String[] GetDataTimeParams(String[] _timestamp,
			boolean iHardCodeStartTime)
	{
		String starttime, endtime;

		if (iHardCodeStartTime)
			starttime = "2010-01-01_010101"; // hard code to sync with iphone
										// side
		else
			starttime = DateUtils.formatDate(
					DateUtils.getDateBefore(new Date(), 7),
					START_DATETIME_FORMAT);

		if (_timestamp != null
				&& _timestamp.length >= 1
				&& _timestamp[_timestamp.length - 1] != null
				&& _timestamp[_timestamp.length - 1].length() >= FETCH_DATETIME_LENGTH)
		{
			String endTimeStamp = _timestamp[_timestamp.length - 1];

			TDStockLog.d(
					LOG_TAG,
					"last datetime: "
							+ endTimeStamp.substring(0,
									FETCH_DATETIME_LENGTH));

			Date lastEndTime = DateUtils.strToDate(
					endTimeStamp.substring(0, FETCH_DATETIME_LENGTH),
					SOURCE_DATETIME_FORMAT);
			Date theEndTime = DateUtils.getRecentDateTime(lastEndTime, -1);

			endtime = DateUtils.formatDate(theEndTime, DEST_DATETIME_FORMAT);

			TDStockLog.d(LOG_TAG, "prepared endtime: " + endtime);
		}
		else
		{
			endtime = String.format(DEST_PARAM_DATETIME_FORMAT,
					calendar.get(Calendar.YEAR),
					(1 + calendar.get(Calendar.MONTH)),
					calendar.get(Calendar.DATE),
					calendar.get(Calendar.HOUR_OF_DAY),
					calendar.get(Calendar.MINUTE),
					calendar.get(Calendar.SECOND));
		}

		TDStockLog.d(LOG_TAG, "Time=>" + starttime + "," + endtime);
		return new String[] { starttime, endtime };
	}

	static public String[] GetDataTimeParamsByYear(String _timestamp)
	{
		String starttime, endtime;

		// starttime = "2012-02-02_010101";
		starttime = DateUtils.formatDate(
				DateUtils.getDateBefore(new Date(), 365),
				START_DATETIME_FORMAT);

		if (_timestamp != null
				&& _timestamp.length() >= FETCH_DATETIME_LENGTH)
		{
			String endTimeStamp = _timestamp;

			TDStockLog.d(
					LOG_TAG,
					"last datetime: "
							+ endTimeStamp.substring(0,
									FETCH_DATETIME_LENGTH));

			Date lastEndTime = DateUtils.strToDate(
					endTimeStamp.substring(0, FETCH_DATETIME_LENGTH),
					SOURCE_DATETIME_FORMAT);
			Date theEndTime = DateUtils.getRecentDateTime(lastEndTime, -1);

			endtime = DateUtils.formatDate(theEndTime, DEST_DATETIME_FORMAT);

			TDStockLog.d(LOG_TAG, "prepared endtime: " + endtime);
		}
		else
		{
			endtime = String.format(DEST_PARAM_DATETIME_FORMAT,
					calendar.get(Calendar.YEAR),
					(1 + calendar.get(Calendar.MONTH)),
					calendar.get(Calendar.DATE),
					calendar.get(Calendar.HOUR_OF_DAY),
					calendar.get(Calendar.MINUTE),
					calendar.get(Calendar.SECOND));
		}

		TDStockLog.d(LOG_TAG, "Time=>" + starttime + "," + endtime);
		return new String[] { starttime, endtime };
	}

	/* Tab Stock */

	static final private String	URL_STOCKNEWS_LIST_TOSTRING	= "http://#FromServer#/iphone/stknews.do?type=NewsList&starttime=%s&endtime=%s&stockcode=%s&last="
															+ PAGE_SIZE
															+ "&filter=YES&account=#AccountNumber#&token=#TokenKey#";

	static public H_CODE SendStockNewsListRequest(Context iContext,
			String iStartTime, String iEndTime, String iStockCode,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName()
				+ "_Stock_News_List_" + iStockCode + "_" + iStartTime + "_"
				+ iEndTime;

		String iRootName = "NewsList";
		String iEntityRootName = "News";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = { "ID", "Title", "DateTime", "Vendor" };

		H_CODE statusCode;
		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);
		statusCode = SendHttpRequest(iContext, catingTag, String.format(
				URL_STOCKNEWS_LIST_TOSTRING, iStartTime, iEndTime,
				iStockCode), iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String	URL_STOCKNEWS_CONTENT_TOSTRING	= "http://#FromServer#/iphone/stknews.do?type=NewsContent&id=%s&vendor=%s&account=#AccountNumber#&token=#TokenKey#";

	static public H_CODE SendStockNewsContentRequest(Context iContext,
			String iID, String iVendor,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName()
				+ "_Stock_News_Content_" + iID + "_" + iVendor;

		String iRootName = "NewsList";
		String iEntityRootName = "News";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = { "DateTime", "Title", "Content", "Status",
				"ErrorMessage" };

		H_CODE statusCode;
		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);
		statusCode = SendHttpRequest(
				iContext,
				catingTag,
				String.format(URL_STOCKNEWS_CONTENT_TOSTRING, iID, iVendor),
				iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String	URL_WARRANT_SEARCH_TOSTRING	= "http://#FromServer#/iphone/searchwarrants.do?stockcode=%s&warranttype=%s&callput=%s&expiremonth=%s&exerprice=%s&premium=%s&percentout=%s&account=#AccountNumber#&token=#TokenKey#";

	static public H_CODE SendWarrantSearchRequest(Context iContext,
			String iStockCode, String[] iParams,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		String catingTag = iContext.getClass().getName() + "_Stock_Search_"
				+ iStockCode;
		for (int i = 0; i < iParams.length; i++)
		{
			catingTag += "_" + iParams[i];
		}

		String iRootName = "SearchItem";
		String iEntityRootName = "Stock";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = { "StockCode", "StockName" };

		H_CODE statusCode;
		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);
		statusCode = SendHttpRequest(iContext, catingTag,
				String.format(URL_WARRANT_SEARCH_TOSTRING, iStockCode,
						iParams[0], iParams[1], iParams[2], iParams[3],
						iParams[4], iParams[5]), iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String	URL_STOCK_SEARCH_TOSTRING	= "http://#FromServer#/iphone/getStockCodeByName.do?name=%s&lastcode=%s&account=#AccountNumber#&token=#TokenKey#";

	static public H_CODE SendStockSearchRequest(Context iContext,
			String iName, String iLastCode,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName()
				+ "_Stock_Search_" + iName + "_" + iLastCode;

		String iRootName = "SearchResult";
		String iEntityRootName = "Stock";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = { "StockCode", "ChiName" };

		H_CODE statusCode;
		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);
		statusCode = SendHttpRequest(iContext, catingTag,
				String.format(URL_STOCK_SEARCH_TOSTRING, iName, iLastCode),
				iResultHandler, iSeqID);

		return statusCode;
	}

	/* Tab Monitor */

	static final private String	URL_DJF_NEWSLIST_TOStTRING	= "http://#FromServer#/iphone/stknews.do?type=NewsList&vendor=%s&catid=%s&last="
															+ PAGE_SIZE
															+ "&omithtml=false&account=#AccountNumber#&token=#TokenKey#";

	// static final private String URL_DJF_NEWSLIST_TOStTRING =
	// "http://#FromServer#/iphone/stknews.do?type=NewsList&vendor=%s&catid=%s&last="
	// + PAGE_SIZE + "&account=#AccountNumber#&token=#TokenKey#";
	static public H_CODE SendDjFNewsListRequest(Context iContext,
			String iVendor, String iCatID,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		return SendDjFNewsListRequest(iContext, iVendor, iCatID, null, null,
				iResultHandler, iSeqID);
	}

	static public H_CODE SendDjFNewsListRequest(Context iContext,
			String iVendor, String iCatID, String iStartTime,
			String iEndTime,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName()
				+ "_NewsList_DjF_" + iVendor + "_" + iCatID + "_"
				+ iStartTime + "_" + iEndTime;

		String iRootName = "NewsList";
		String iEntityRootName = "News";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = { "ID", "DateTime", "Title" };

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;

		String urlToString = String.format(URL_DJF_NEWSLIST_TOStTRING,
				iVendor, iCatID);

		if (iStartTime != null && iEndTime != null)
		{
			urlToString = String.format(urlToString
					+ "&starttime=%s&endtime=%s", iStartTime, iEndTime);
		}

		statusCode = SendHttpRequest(iContext, catingTag, urlToString,
				iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String	URL_DJF_NEWSCONTENT_TOSTRING	= "http://#FromServer#/iphone/stknews.do?type=NewsContent&vendor=%s&id=%s&omithtml=false&account=#AccountNumber#&token=#TokenKey#";

	// static final private String URL_DJF_NEWSCONTENT_TOSTRING =
	// "http://#FromServer#/iphone/stknews.do?type=NewsContent&vendor=%s&id=%s&account=#AccountNumber#&token=#TokenKey#";
	static public H_CODE SendDjFNewsContentRequest(Context iContext,
			String iVendor, String iID,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName()
				+ "_NewsContent_DjF_" + iVendor + "_" + iID;

		String iRootName = "NewsList";
		String iEntityRootName = "News";
		String[] iHeaderFieldNames = { "Status", "ErrorMessage" };
		String[] iFieldNames = { "DateTime", "Title", "Content" };

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequest(iContext, catingTag,
				String.format(URL_DJF_NEWSCONTENT_TOSTRING, iVendor, iID),
				iResultHandler, iSeqID);

		return statusCode;
	}

	/* Tab Index */

	static final private String[]	URL_INDEXOPTION_TOSTRING	= {
			"http://#FromServer#/iphone/financeAction.do?type=HKSF&account=#AccountNumber#&token=#TokenKey#",
			"",
			"http://#FromServer#/iphone/stkHolidayAction.do?account=#AccountNumber#&token=#TokenKey#",
			"http://#FromServer#/iphone/getMarketDaylightSaving.do?account=#AccountNumber#&token=#TokenKey#" };

	static public H_CODE SendIndexOptionContentRequest(Context iContext,
			int iTypeId,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName()
				+ "_IndexOption_" + iTypeId;
		String[] iRtNames = { "Finance", "", "StockMarketHoliday", "Finance" };
		String[] iERNames = { "HKSF", "", "StockMarketHoliday",
				"MarketDaylightSaving" };
		String[][] iHFNames = { null, null, { "Content" }, null };
		String[][] iFNames = {
				{ "Message" },
				{ "" },
				{ "" },
				{ "Location", "StartDate", "EndDate", "OriginalStartTime",
						"NewStartTime" } };

		String iRootName = iRtNames[iTypeId];
		String iEntityRootName = iERNames[iTypeId];
		String[] iHeaderFieldNames = iHFNames[iTypeId];
		String[] iFieldNames = iFNames[iTypeId];

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequest(iContext, catingTag,
				URL_INDEXOPTION_TOSTRING[iTypeId], iResultHandler, iSeqID);

		return statusCode;
	}

	/* Tab Forex */

	static final private String	URL_FX_RATERMB_TOSTRING	= "http://#FromServer#/iphone/getcnyfx.do?name=EURCNY,GBPCNY,HKDCNY,JPYCNY,USDCNY&hist=%s&account=#AccountNumber#&token=#TokenKey#";

	static public H_CODE SendFXRateRMBRequest(Context iContext,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName() + "_FXRateRMB";

		String iRootName = "FXLIST";
		String iEntityRootName = "FXRMB";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = { "NAME", "LAST", "TIMESTAMP" };

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		Date lastWeekDay = DateUtils.getDateBefore(new Date(), 20);
		String tmp = DateUtils.formatDate(lastWeekDay, "yyyy-MM-dd");

		H_CODE statusCode;
		statusCode = SendHttpRequest(iContext, catingTag,
				String.format(URL_FX_RATERMB_TOSTRING, tmp),
				iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String	URL_FX_CURRENCY_TOSTRING	= "http://#FromServer#/iphone/getFxBank.do?account=#AccountNumber#&token=#TokenKey#";

	static public H_CODE SendFXCurrencyRequest(Context iContext,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName()
				+ "_FXCurrency";

		String iRootName = "Finance";
		String iEntityRootName = "BankCurrency";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = { "Remark", "Bid", "Ask", "Name" };

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequest(iContext, catingTag,
				URL_FX_CURRENCY_TOSTRING, iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String	URL_FX_ECONOMICCALENDAR_TOSTRING	= "http://#FromServer#/iphone/forexCalendarAction.do?account=#AccountNumber#&token=#TokenKey#";

	static public H_CODE SendFXEconomicRequest(Context iContext, int iTypeId,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName()
				+ "_FXEconomic_" + iTypeId;

		String[] iERootName = { "Mon", "Tue", "Wed", "Thu", "Fri" };

		String iRootName = "FX";
		String iEntityRootName = iERootName[iTypeId];
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = { "Message" };

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequest(iContext, catingTag,
				URL_FX_ECONOMICCALENDAR_TOSTRING, iResultHandler, iSeqID);

		return statusCode;
	}

	/* Tab More */

	static final private String	URL_ADR_TOSTRING	= "http://#FromServer#/iphone/stockAdrAction.do?account=#AccountNumber#&token=#TokenKey#";

	static public H_CODE SendADRRequest(Context iContext,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName() + "_ADR";

		String iRootName = "Finance";
		String iEntityRootName = "Stock";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = { "StockCode", "SchiName", "PriceHKD", "NET" };

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequest(iContext, catingTag, URL_ADR_TOSTRING,
				iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String	URL_OIL_TOSTRING	= "http://#FromServer#/iphone/getoilquote.do?account=#AccountNumber#&token=#TokenKey#";

	static public H_CODE SendOilQuoteRequest(Context iContext,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName() + "_QIL";

		String iRootName = "OILLIST";
		String iEntityRootName = "OIL";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = { "LAST", "NET", "PREV", "HIGH", "LOW" };

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequest(iContext, catingTag, URL_OIL_TOSTRING,
				iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String	URL_OIL_PREVCLOSE_TOSTRING	= "http://#FromServer#/iphone/getoilquote.do?hist=all&account=#AccountNumber#&token=#TokenKey#";

	static public H_CODE SendOilQuotePrevCloseRequest(Context iContext,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName() + "_QIL_ALL";

		String iRootName = "OILLIST";
		String iEntityRootName = "OIL";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = { "TIMESTAMP", "LAST", "NET" };

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequest(iContext, catingTag,
				URL_OIL_PREVCLOSE_TOSTRING, iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String	URL_AHCOMPARISON_TOSTRING	= "http://#FromServer#/iphone/ahComp.do?type=AHComparison&account=#AccountNumber#&token=#TokenKey#";

	static public H_CODE SendAHComparisonRequest(Context iContext,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName() + "_AH";

		String iRootName = "SearchItem";
		String iEntityRootName = "Stock";
		String[] iHeaderFieldNames = { "", "ExchangeRate", "", "", "" };
		String[] iFieldNames = { "StockCode", "StockName", "HNominal",
				"ANominal", "Pencent" };

		H_CODE statusCode;
		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);
		statusCode = SendHttpRequest(iContext, catingTag,
				URL_AHCOMPARISON_TOSTRING, iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String	URL_AHCOMPARISON_HIST_TOSTRING	= "http://#FromServer#/iphone/ahComp.do?type=AHComparisonHist&account=#AccountNumber#&token=#TokenKey#";

	static public H_CODE SendAHComparisonHistRequest(Context iContext,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName() + "_AH_Hist";

		String iRootName = "SearchItem";
		String iEntityRootName = "Stock";
		String[] iHeaderFieldNames = { "", "ExchangeRate", "OneDDate",
				"TwoDDate", "WDate" };
		String[] iFieldNames = { "StockCode", "StockName", "OneDPercent",
				"TwoDPercent", "WPercent" };

		H_CODE statusCode;
		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);
		statusCode = SendHttpRequest(iContext, catingTag,
				URL_AHCOMPARISON_HIST_TOSTRING, iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String[]	URL_INSTANT_MARKET_TOSTRING	= {
			"http://#FromServer#/iphone/stkSusp.do?type=TodaySuspended&account=#AccountNumber#&token=#TokenKey#",
			"http://#FromServer#/iphone/stkSusp.do?type=Suspended&account=#AccountNumber#&token=#TokenKey#",
			"http://#FromServer#/iphone/stkSusp.do?type=Resumed&account=#AccountNumber#&token=#TokenKey#",
			"http://#FromServer#/iphone/stkExtra.do?type=Results&account=#AccountNumber#&token=#TokenKey#",
			"http://#FromServer#/iphone/stkExtra.do?type=EXDate&account=#AccountNumber#&token=#TokenKey#",
			"http://#FromServer#/iphone/stkExtra.do?type=DivDate&account=#AccountNumber#&token=#TokenKey#",
			"http://#FromServer#/iphone/spCurrency.do?account=#AccountNumber#&token=#TokenKey#", };

	static public H_CODE SendInstantMarketRequest(Context iContext,
			int iTypeId,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName()
				+ "_InstantMarket_" + iTypeId;

		String iRootName = "InstantMarket";
		String iEntityRootName = "Stock";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = null;

		switch (iTypeId)
		{
			case 0:
			case 1:
			case 2:
			case 4:
				iFieldNames = new String[] { "Timestamp", "StockCode",
						"StockName" };
				break;
			case 3:
				iFieldNames = new String[] { "StockCode", "StockName",
						"ReportType", "Timestamp" };
				break;
			case 5:
				iFieldNames = new String[] { "StockCode", "StockName",
						"Timestamp", "DivType" };
				break;
			case 6:
				iFieldNames = new String[] { "StockCode", "CurrencyCode" };
				break;
		}

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequest(iContext, catingTag,
				URL_INSTANT_MARKET_TOSTRING[iTypeId], iResultHandler,
				iSeqID);

		return statusCode;
	}

	static final private String[]	URL_SHORTSELL_TOSTRING	= {
			"http://#FromServer#/iphone/shortSell.do?type=ShortsellNoon&account=#AccountNumber#&token=#TokenKey#",
			"http://#FromServer#/iphone/shortSell.do?type=ShortsellDaily&account=#AccountNumber#&token=#TokenKey#",
			"http://#FromServer#/iphone/shortSell.do?type=ShortsellWeekly&account=#AccountNumber#&token=#TokenKey#" };

	static public H_CODE SendShortSellActivity(Context iContext, int iTypeId,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName()
				+ "_ShortSell_" + iTypeId;

		String iRootName = "InstantMarket";
		String iEntityRootName = "Stock";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = null;

		switch (iTypeId)
		{
			case 0:
			case 1:
				iFieldNames = new String[] { "StockCode", "StockName",
						"Turnover", "Timestamp" };
				break;
			case 2:
				iHeaderFieldNames = new String[] { "FromDate", "ToDate", "" };
				iFieldNames = new String[] { "StockCode", "StockName",
						"Turnover" };
				break;
		}

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequest(iContext, catingTag,
				URL_SHORTSELL_TOSTRING[iTypeId], iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String[]	URL_ANALYSIS_TOSTRING	= {
			"http://#FromServer#/iphone/stkanalysis.do?type=IPOPerformance&account=#AccountNumber#&token=#TokenKey#",
			"http://#FromServer#/iphone/stkanalysis.do?type=MarketMove&account=#AccountNumber#&token=#TokenKey#",
			"http://#FromServer#/iphone/stkanalysis.do?type=OverMA10&account=#AccountNumber#&token=#TokenKey#",
			"http://#FromServer#/iphone/stkanalysis.do?type=BelowMA10&account=#AccountNumber#&token=#TokenKey#",
			"http://#FromServer#/iphone/stkanalysis.do?type=OverYearHigh&account=#AccountNumber#&token=#TokenKey#",
			"http://#FromServer#/iphone/stkanalysis.do?type=BelowYearLow&account=#AccountNumber#&token=#TokenKey#",
			"http://#FromServer#/iphone/stkanalysis.do?type=ExpiringWarrants&account=#AccountNumber#&token=#TokenKey#",
			"http://#FromServer#/iphone/stkanalysis.do?type=OutOfTheMoneyToInTheMoney&account=#AccountNumber#&token=#TokenKey#" };

	static public H_CODE SendAnalysisRequest(Context iContext, int iTypeId,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName() + "_Analyisi_"
				+ iTypeId;

		String iRootName = "Analysis";
		String iEntityRootName = "Stock";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = null;

		switch (iTypeId)
		{
			case 0:
				iFieldNames = new String[] { "StockCode", "StockName",
						"Nominal", "CompareToIPO" };
				break;
			case 1:
				iFieldNames = new String[] { "StockCode", "StockName",
						"Nominal", "ShareTradedIncrease" };
				break;
			case 2:
			case 3:
			case 4:
			case 5:
				iFieldNames = new String[] { "StockCode", "StockName",
						"Nominal" };
				break;
			case 6:
			case 7:
				iFieldNames = new String[] { "StockCode", "CallPut",
						"StockName", "Nominal" };
				break;
		}

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequest(iContext, catingTag,
				URL_ANALYSIS_TOSTRING[iTypeId], iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String[]	URL_FINANCE_TOSTRING	= {
			"",
			"http://#FromServer#/iphone/financeAction.do?type=FinancialData&account=#AccountNumber#&token=#TokenKey#",
			"http://#FromServer#/iphone/financeAction.do?type=MIBCommentary&account=#AccountNumber#&token=#TokenKey#",
			"http://#FromServer#/iphone/financeAction.do?type=InterestRate&account=#AccountNumber#&token=#TokenKey#",
			"",
			"http://#FromServer#/iphone/financeAction.do?type=GuocoCommentary&account=#AccountNumber#&token=#TokenKey#",
			"http://#FromServer#/iphone/financeAction.do?type=FirstshCommentary&account=#AccountNumber#&token=#TokenKey#" };

	static public H_CODE SendFinanceRequest(Context iContext, int iTypeId,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName() + "_Finance_"
				+ iTypeId;

		String[] allEntityRooNames = { "-1", "FinancialData",
				"MIBCommentary", "InterestRate", "-1", "Commentary",
				"Commentary" };

		String[][] allFieldNames = { {}, { "Message" },
				{ "Desc", "Message" }, { "Desc", "Last" }, {},
				{ "Message" }, { "Message" } };

		String iRootName = "Finance";
		String iEntityRootName = allEntityRooNames[iTypeId];
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = allFieldNames[iTypeId];

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequest(iContext, catingTag,
				URL_FINANCE_TOSTRING[iTypeId], iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String[]	URL_WARRANTS_TOSTRING	= {
			"http://#FromServer#/iphone/warrantsAction.do?type=KBCCommentary&timestamp=%s&account=#AccountNumber#&token=#TokenKey#",
			"http://#FromServer#/iphone/warrantsAction.do?type=SGCommentary&timestamp=%s&account=#AccountNumber#&token=#TokenKey#",
			"http://#FromServer#/iphone/warrantsAction.do?type=DBCommentary&timestamp=%s&account=#AccountNumber#&token=#TokenKey#" };

	static public H_CODE SendWarrantsRequest(Context iContext, int iTypeId,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName() + "_Warrants_"
				+ iTypeId;

		String iRootName = "Finance";
		String iEntityRootName = "Commentary";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = { "NewsID", "CatID", "StoryDesct",
				"StoryText", "Timestamp" };

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		Date now = new Date();
		Date last30day = DateUtils.getDateBefore(now, 30);

		calendar.setTime(last30day);

		String timestamp = String.format("%d-%02d-%02d_%02d%02d%02d",
				calendar.get(Calendar.YEAR), last30day.getMonth() + 1,
				last30day.getDate(), last30day.getHours(),
				last30day.getMinutes(), last30day.getSeconds()); // 2011-01-13_115120

		H_CODE statusCode;
		statusCode = SendHttpRequest(iContext, catingTag,
				String.format(URL_WARRANTS_TOSTRING[iTypeId], timestamp),
				iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String	URL_IPO_TOSTRING	= "http://#FromServer#/iphone/stockIpoAction.do?account=#AccountNumber#&token=#TokenKey#";

	static public H_CODE SendIPORequest(Context iContext,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName() + "_Ipo";

		String iRootName = "InstantMarket";
		String iEntityRootName = "IPO";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = { "Message" };

		SetIsFieldValueList(true);
		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequest(iContext, catingTag, URL_IPO_TOSTRING,
				iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String	URL_CHECKUSAGE_TOSTRING	= "http://#FromServer#/iphone/getRealstockUsage.do?account=#AccountNumber#&token=#TokenKey#";

	static public H_CODE SendCheckUsageRequest(Context iContext,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName()
				+ "_CheckUsage";

		String iRootName = "RealStockUsage";
		String iEntityRootName = "RealStockUsage";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = { "Account", "EndDate", "Usage" };

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequest(iContext, catingTag,
				URL_CHECKUSAGE_TOSTRING, iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String	URL_STOCKSTAR_TOSTRING	= "http://#FromServer#/iphone/getStockStar.do?starid=%s&starttime=%s&endtime=%s&last="
														+ PAGE_SIZE
														+ "&account=#AccountNumber#&token=#TokenKey#";

	static public H_CODE SendStockStarRequest(Context iContext,
			String iTypeName, String iStartTime, String iEndTime,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName()
				+ "_Stock_Star_" + iTypeName + "_" + iStartTime + "_"
				+ iEndTime;

		String iRootName = "StockStar";
		String iEntityRootName = "StockStar";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = { "Message" };

		// String[] iEntityRootNameAttributes = null;
		String[] iFieldNameAttributes = { "Datetime" };

		SetFieldNameAttributes(iFieldNameAttributes);

		SetIsFieldValueList(true);
		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequest(iContext, catingTag, String.format(
				URL_STOCKSTAR_TOSTRING, iTypeName, iStartTime, iEndTime),
				iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String	URL_STOCKSTAR_INDEX_TOSTRING	= "http://#FromServer#/iphone/getStockStar.do?account=#AccountNumber#&token=#TokenKey#";

	static public H_CODE SendStockStarIndexRequest(Context iContext,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName()
				+ "_Stock_Star_Index";

		String iRootName = "StockStarIndex";
		String iEntityRootName = "StockStar";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = { "Message" };

		// String[] iEntityRootNameAttributes = { "StarId", "StarName" };
		// String[] iFieldNameAttributes = { "Datetime" };
		//
		// SetFieldNameAttributes(iFieldNameAttributes);

		SetIsFieldValueList(true);
		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequest(iContext, catingTag,
				URL_STOCKSTAR_INDEX_TOSTRING, iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String	URL_STOCKSECTOR_TOSTRING	= "http://#FromServer#/iphone/getStockSectorSc.do?sector=%s&account=#AccountNumber#&token=#TokenKey#";

	static public H_CODE SendStockSectorRequest(Context iContext,
			String iTypeName,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName()
				+ "_Stock_Sector_" + iTypeName;

		String iRootName = "Stock";
		String iEntityRootName = "StockSectorScode";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = { "StockCode" };

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequest(iContext, catingTag,
				String.format(URL_STOCKSECTOR_TOSTRING, iTypeName),
				iResultHandler, iSeqID);

		return statusCode;
	}

	// BMP Mode
	static final private String	URL_BMP_TIME_TOSTRING	= "http://#FromServer#/iphone/getTime.do";

	static public H_CODE SendBMPTimeRequest(Context iContext,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName() + "_BMP_Time";

		String iRootName = "Time";
		String iEntityRootName = null;
		String[] iHeaderFieldNames = { "Time" };
		String[] iFieldNames = null;

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequest(iContext, catingTag,
				URL_BMP_TIME_TOSTRING, iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String	URL_BMP_STOCK_TOSTRING	= "http://#FromServer#/stock/get.do?stockcode=%s&detail=all&account=#AccountNumber#&token=#TokenKey#&jckey=1";

	static public H_CODE SendBMPStockMonitorRequest(Context iContext,
			String iTypeName,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName()
				+ "_BMP_Stock_Monitor_" + iTypeName;

		String iRootName = "STOCKLIST";
		String iEntityRootName = "STOCK";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = Stock.FIELD_ITEMS_MONITOR;

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequestBMPConvertMapObject(iContext,
				Stock.class, BMPPage.MONITOR, catingTag,
				String.format(URL_BMP_STOCK_TOSTRING, iTypeName),
				iResultHandler, iSeqID);

		return statusCode;
	}

	static public H_CODE SendStockSectorMonitorRequest(Context iContext,
			String iTypeName,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName()
				+ "_Stock_Sector_Monitor_" + iTypeName;

		String iRootName = "STOCKLIST";
		String iEntityRootName = "STOCK";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = Stock.FIELD_ITEMS_MONITOR;

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequestBMPConvertListObject(iContext,
				Stock.class, BMPPage.MONITOR, catingTag,
				String.format(URL_BMP_STOCK_TOSTRING, iTypeName),
				iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String	URL_BMP_TOP20_TOSTRING	= "http://#FromServer#/iphone/getActive.do?act=%s&account=#AccountNumber#&token=#TokenKey#&jckey=1";

	static public H_CODE SendBMPTop20Request(Context iContext,
			String iTypeName, boolean iIsNet,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName()
				+ "_BMP_Top20Stock_" + iTypeName + "_" + iIsNet;

		String iRootName = "Analysis";
		String iEntityRootName = "Stock1,Stock2,Stock3,Stock4,Stock5,Stock6,Stock7,Stock8,Stock9,Stock10,Stock11,Stock12,Stock13,Stock14,Stock15,Stock16,Stock17,Stock18,Stock19,Stock20";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = iIsNet ? Top20Stock.FIELD_ITEMS_NET
				: Top20Stock.FIELD_ITEMS_TURNOVER;

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequestBMPConvertListObject(iContext,
				Top20Stock.class, iIsNet ? BMPPage.TOP20_NET
						: BMPPage.TOP20_TURNOVER, catingTag,
				String.format(URL_BMP_TOP20_TOSTRING, iTypeName),
				iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String	URL_BMP_INDEX_TOSTRING	= "http://#FromServer#/stock/get.do?detail=INDEX&stockcode=%s&account=#AccountNumber#&token=#TokenKey#&jckey=1";

	static public H_CODE SendBMPIndexStockRequest(Context iContext,
			final String iTypeName,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		return SendBMPIndexRequest(iContext, BMPPage.STOCK, iTypeName,
				iResultHandler, iSeqID);
	}

	static public H_CODE SendBMPIndexMonitorRequest(Context iContext,
			String iTypeName,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		return SendBMPIndexRequest(iContext, BMPPage.MONITOR, iTypeName,
				iResultHandler, iSeqID);
	}

	static public H_CODE SendBMPIndexCurrentRequest(Context iContext,
			String iTypeName,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		return SendBMPIndexRequest(iContext, BMPPage.CURRENT, iTypeName,
				iResultHandler, iSeqID);
	}

	static private H_CODE SendBMPIndexRequest(Context iContext,
			final BMPPage iBmpPage, final String iTypeName,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName()
				+ "_BMP_Index_" + iBmpPage + "_" + iTypeName;

		String iRootName = "STOCKLIST";
		String iEntityRootName = "STOCK";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = Index.FIELD_ITEMS;

		if (BMPPage.STOCK == iBmpPage)
		{
			iFieldNames = Index.FIELD_ITEMS_STOCK;
		}
		else if (BMPPage.MONITOR == iBmpPage)
		{
			iFieldNames = Index.FIELD_ITEMS_MONITOR;
		}

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequestBMPConvertMapObject(iContext,
				Index.class, iBmpPage, catingTag,
				String.format(URL_BMP_INDEX_TOSTRING, iTypeName),
				iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String	URL_BMP_FUTURES_TOSTRING	= "http://#FromServer#/stock/getFutureHk.do?name=%s&delay=%s&account=#AccountNumber#&token=#TokenKey#&jckey=1";

	static public H_CODE SendBMPFuturesCurrentRequest(Context iContext,
			boolean iDelay,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		return SendBMPFuturesRequest(iContext, BMPPage.CURRENT,
				Futures.TypeName_Str, iDelay, iResultHandler, iSeqID);
	}

	static public H_CODE SendBMPFuturesStockRequest(Context iContext,
			String iTypeName, boolean iDelay,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		return SendBMPFuturesRequest(iContext, BMPPage.STOCK, iTypeName,
				iDelay, iResultHandler, iSeqID);
	}

	static public H_CODE SendBMPFuturesMonitorRequest(Context iContext,
			String iTypeName, boolean iDelay,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		return SendBMPFuturesRequest(iContext, BMPPage.MONITOR, iTypeName,
				iDelay, iResultHandler, iSeqID);
	}

	static public H_CODE SendBMPFuturesCOPRequest(Context iContext,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		return SendBMPFuturesRequest(iContext, BMPPage.COP,
				Futures.TypeName_Str, false, iResultHandler, iSeqID);
	}

	static private H_CODE SendBMPFuturesRequest(Context iContext,
			BMPPage iBmpPage, String iTypeName, boolean iDelay,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName()
				+ "_BMP_Futures_" + iBmpPage + "_" + iTypeName + "_"
				+ iDelay;

		String iRootName = "Future";
		String iEntityRootName = "Index";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = Futures.FIELD_ITEMS;

		if (BMPPage.STOCK == iBmpPage)
		{
			iFieldNames = Futures.FIELD_ITEMS_STOCK;
		}
		else if (BMPPage.MONITOR == iBmpPage)
		{
			iFieldNames = Futures.FIELD_ITEMS_MONITOR;
		}
		else if (BMPPage.COP == iBmpPage)
		{
			iFieldNames = Futures.FIELD_ITEMS_COP;
		}

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequestBMPConvertMapObject(iContext,
				Futures.class, iBmpPage, catingTag,
				String.format(URL_BMP_FUTURES_TOSTRING, iTypeName, iDelay),
				iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String	URL_BMP_WORLDINDEX_TOSTRING	= "http://#FromServer#/iphone/get.do?detail=WIDX&name=%s&account=#AccountNumber#&token=#TokenKey#&jckey=1";

	static public H_CODE SendBMPWorldIndexCurrentRequest(Context iContext,
			final String iTypeName,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		return SendBMPWorldIndexRequest(iContext, BMPPage.CURRENT, iTypeName,
				iResultHandler, iSeqID);
	}

	static public H_CODE SendBMPWorldIndexMonitorRequest(Context iContext,
			final String iTypeName,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		return SendBMPWorldIndexRequest(iContext, BMPPage.MONITOR, iTypeName,
				iResultHandler, iSeqID);
	}

	static private H_CODE SendBMPWorldIndexRequest(Context iContext,
			final BMPPage iBmpPage, final String iTypeName,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName()
				+ "_BMP_WorldIndex_" + iBmpPage + "_" + iTypeName;

		String iRootName = "Index";
		String iEntityRootName = "WorldIndex";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = WorldIndex.FIELD_ITEMS;

		if (BMPPage.MONITOR == iBmpPage)
		{
			iFieldNames = WorldIndex.FIELD_ITEMS_MONITOR;
		}

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequestBMPConvertMapObject(iContext,
				WorldIndex.class, iBmpPage, catingTag,
				String.format(URL_BMP_WORLDINDEX_TOSTRING, iTypeName),
				iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String	URL_BMP_WORLDINDEX_SSEI_TOSTRING	= "http://#FromServer#/stock/getworldindex.do?name=%s&delay=%s&account=#AccountNumber#&token=#TokenKey#&jckey=1";

	static public H_CODE SendBMPWorldIndexSSEICurrentRequest(Context iContext,
			final String iTypeName, final boolean iDelay,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		return SendBMPWorldIndexSSEIRequest(iContext, BMPPage.CURRENT,
				iTypeName, iDelay, iResultHandler, iSeqID);
	}

	static public H_CODE SendBMPWorldIndexSSEIMonitorRequest(Context iContext,
			final String iTypeName, final boolean iDelay,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		return SendBMPWorldIndexSSEIRequest(iContext, BMPPage.MONITOR,
				iTypeName, iDelay, iResultHandler, iSeqID);
	}

	static private H_CODE SendBMPWorldIndexSSEIRequest(Context iContext,
			final BMPPage iBmpPage, final String iTypeName,
			final boolean iDelay,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName()
				+ "_BMP_WorldIndex_SSEI_" + iBmpPage + "_" + iTypeName
				+ "_" + iDelay;

		String iRootName = "Index";
		String iEntityRootName = "WorldIndex";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = WorldIndex.FIELD_ITEMS;

		if (BMPPage.MONITOR == iBmpPage)
		{
			iFieldNames = WorldIndex.FIELD_ITEMS_MONITOR;
		}

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequestBMPConvertMapObject(iContext,
				WorldIndex.class, iBmpPage, catingTag, String.format(
						URL_BMP_WORLDINDEX_SSEI_TOSTRING, iTypeName,
						iDelay), iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String	URL_BMP_WORLDFUTURES_TOSTRING	= "http://#FromServer#/stock/getFutureWorld.do?name=%s&account=#AccountNumber#&token=#TokenKey#&jckey=1";

	static public H_CODE SendBMPWorldFuturesCurrentRequest(Context iContext,
			final String iTypeName,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		return SendBMPWorldFuturesRequest(iContext, BMPPage.CURRENT,
				iTypeName, iResultHandler, iSeqID);
	}

	static public H_CODE SendBMPWorldFuturesMonitorRequest(Context iContext,
			final String iTypeName,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		return SendBMPWorldFuturesRequest(iContext, BMPPage.MONITOR,
				iTypeName, iResultHandler, iSeqID);
	}

	static private H_CODE SendBMPWorldFuturesRequest(Context iContext,
			final BMPPage iBmpPage, final String iTypeName,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName()
				+ "_BMP_WorldFutures_" + iBmpPage + "_" + iTypeName;

		String iRootName = "Future";
		String iEntityRootName = "Index";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = WorldFutures.FIELD_ITEMS;

		if (BMPPage.MONITOR == iBmpPage)
		{
			iFieldNames = WorldFutures.FIELD_ITEMS_MONITOR;
		}

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequestBMPConvertMapObject(iContext,
				WorldFutures.class, iBmpPage, catingTag,
				String.format(URL_BMP_WORLDFUTURES_TOSTRING, iTypeName),
				iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String	URL_BMP_FX_TOSTRING	= "http://#FromServer#/stock/getbocfx.do?name=%s&account=#AccountNumber#&token=#TokenKey#&jckey=1";

	static public H_CODE SendBMPFXMonitorRequest(Context iContext,
			final String iTypeName,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName()
				+ "_BMP_FX_Monitor_" + iTypeName;

		String iRootName = "FXLIST";
		String iEntityRootName = "FX";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = Fx.FIELD_ITEMS_MONITOR;

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequestBMPConvertMapObject(iContext, Fx.class,
				BMPPage.MONITOR, catingTag,
				String.format(URL_BMP_FX_TOSTRING, iTypeName),
				iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String	URL_BMP_METAL_TOSTRING	= "http://#FromServer#/stock/getmetalquote.do?name=%s&account=#AccountNumber#&token=#TokenKey#&jckey=1";

	static public H_CODE SendBMPMetalMonitorRequest(Context iContext,
			final String iTypeName,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName()
				+ "_BMP_Metal_Monitor_" + iTypeName;

		String iRootName = "METALLIST";
		String iEntityRootName = "METAL";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = Metal.FIELD_ITEMS_MONITOR;

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequestBMPConvertMapObject(iContext,
				Metal.class, BMPPage.MONITOR, catingTag,
				String.format(URL_BMP_METAL_TOSTRING, iTypeName),
				iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String	URL_BMP_OIL_TOSTRING	= "http://#FromServer#/iphone/getoilquote.do?account=#AccountNumber#&token=#TokenKey#&jckey=1";

	static public H_CODE SendBMPOilMonitorRequest(Context iContext,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName()
				+ "_BMP_Oil_Monitor";

		String iRootName = "OILLIST";
		String iEntityRootName = "OIL";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = Oil.FIELD_ITEMS_MONITOR;

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequestBMPConvertMapObject(iContext, Oil.class,
				BMPPage.MONITOR, catingTag, URL_BMP_OIL_TOSTRING,
				iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String	URL_BMP_STOCKPAGE_TOSTRING	= "http://#FromServer#/stock/bmpXmlPrinter.do?stockcode=%s&indexcode=HSI,HSCEI&worldindex=SSE1&futurehk=HSI:1,HSI:2&worldidxdelay=%s&futhkdelay=%s&account=#AccountNumber#&token=#TokenKey#&jckey=1";

	static public H_CODE SendBMPStockPageAllRequest(Context iContext,
			final String iTypeName,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName()
				+ "_BMP_StockPage_All_" + iTypeName;

		String iRootName = "BMP";
		String iEntityRootName = "STOCKLIST,Index,Futures";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = null;

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		ITDLApplication iAppContext = (ITDLApplication) iContext
				.getApplicationContext();
		String wdidxdelay = String.valueOf(!iAppContext.getIsRealtimeSSEI());
		String futhkdelay = String.valueOf(!iAppContext
				.getIsRealtimeFutures());

		H_CODE statusCode;
		statusCode = SendHttpRequestBMPConvertMapObject(iContext, null, null,
				catingTag, String.format(URL_BMP_STOCKPAGE_TOSTRING,
						iTypeName, wdidxdelay, futhkdelay),
				iResultHandler, iSeqID);

		return statusCode;
	}

	static final private String	URL_BMP_MonitoPage_TOSTRING	= "http://#FromServer#/stock/bmpXmlPrinter.do?stockcode=%s&indexcode=%s&worldindex=%s&futurehk=%s&futureworld=%s&fxname=%s&metalname=%s&oil=%s&worldidxdelay=false&futhkdelay=false&account=#AccountNumber#&token=#TokenKey#&jckey=1";

	static public H_CODE SendBMPMonitorPageAllRequest(Context iContext,
			final String[] iTypeName,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String iStockCode = iTypeName[0], iIndexCode = iTypeName[1], iWorldIndexCode = iTypeName[2], iFuturesCode = iTypeName[3], iWorldFuturesCode = iTypeName[4], iFxCode = iTypeName[5], iMetalCode = iTypeName[6], iOilCode = iTypeName[7];

		final String catingTag = iContext.getClass().getName()
				+ "_BMP_MonitorPage_All_" + iStockCode + iIndexCode
				+ iWorldIndexCode + iFuturesCode + iWorldFuturesCode
				+ iFxCode + iMetalCode + iOilCode;

		String iRootName = "BMP";
		String iEntityRootName = "STOCKLIST,Index,Futures,FXLIST,METALLIST,OILLIST";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = null;

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		// ITDLApplication iAppContext =
		// (ITDLApplication)iContext.getApplicationContext();
		// String wdidxdelay = String.valueOf(!iAppContext.getIsRealtimeSSEI());
		// String futhkdelay =
		// String.valueOf(!iAppContext.getIsRealtimeFutures());

		H_CODE statusCode;
		final String iUrl = String.format(URL_BMP_MonitoPage_TOSTRING,
				iStockCode, iIndexCode, iWorldIndexCode, iFuturesCode,
				iWorldFuturesCode, iFxCode, iMetalCode, iOilCode/*
																 * , wdidxdelay,
																 * futhkdelay
																 */);
		statusCode = SendHttpRequestBMPConvertMapObject(iContext, null, null,
				catingTag, iUrl, iResultHandler, iSeqID);

		return statusCode;
	}

	static private String	rtName, etRootName;
	static private String[]	hFieldNames, fdNames;
	static private boolean	iFieldValueList;

	static private void SetIsFieldValueList(boolean iFdValueList)
	{
		iFieldValueList = iFdValueList;
	}

	static private void SetElementNameInformation(final String iRootName,
			final String[] iHeaderFieldNames, final String iEntityRootName,
			final String[] iFieldNames)
	{
		rtName = iRootName;
		etRootName = iEntityRootName;
		hFieldNames = iHeaderFieldNames;
		fdNames = iFieldNames;
	}

	static private String[]	fieldNameAttributes;

	static private void SetFieldNameAttributes(final String[] ifnAttributes)
	{
		fieldNameAttributes = ifnAttributes;
	}

	static private H_CODE SendHttpRequest(Context iContext,
			final String catingTag, final String urlToString,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		return SendHttpRequestBase(iContext, null, null, false, catingTag,
				urlToString, iResultHandler, iSeqID);
	}

	static private H_CODE SendHttpRequestBMPConvertMapObject(Context iContext,
			final Class<?> iCls, final BMPPage iBmpPage,
			final String catingTag, final String urlToString,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		return SendHttpRequestBase(iContext, iCls, iBmpPage, true, catingTag,
				urlToString, iResultHandler, iSeqID);
	}

	static private H_CODE SendHttpRequestBMPConvertListObject(
			Context iContext, final Class<?> iCls, final BMPPage iBmpPage,
			final String catingTag, final String urlToString,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		return SendHttpRequestBase(iContext, iCls, iBmpPage, false,
				catingTag, urlToString, iResultHandler, iSeqID);
	}

	static private H_CODE SendHttpRequestBase(Context iContext,
			final Class<?> iCls, final BMPPage iBmpPage,
			final boolean iMapObj, final String catingTag,
			final String urlToString,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		H_CODE statusCode;
		H_HttpServiceRequest requestCmd;

		if (!isCommunicatingMap.containsKey(catingTag))
			isCommunicatingMap.put(catingTag, false);

		if (debugMode)
			TDStockLog.i(LOG_TAG, catingTag + "-isCommunicating:"
					+ isCommunicatingMap.get(catingTag));

		// Use to block the multiple communication
		if (isCommunicatingMap.get(catingTag))
		{
			iFieldValueList = false;
			fieldNameAttributes = null;
			return H_CODE.SYSTEM_BUSY;
		}
		
		isCommunicatingMap.put(catingTag, true);

		requestCmd = new H_HttpServiceRequest(iContext,
				(iSeqID != null && iSeqID.length > 0) ? iSeqID[0] : "SEQID");
		requestCmd.SetAccountInformation(GetAccountNum(), GetSessionId()); // testing...
																// change
																// sessionkey
																// to
																// error.
		requestCmd.SetFieldAttributes(fieldNameAttributes);
		requestCmd.SetFieldValue(iFieldValueList);
		requestCmd.SetDocumentFieldInformation(rtName, hFieldNames,
				etRootName, fdNames);
		iFieldValueList = false;
		fieldNameAttributes = null;
		statusCode = requestCmd.SubmitRequest(urlToString,
				new IH_UserClient_HttpRequest_Report()
				{
					@Override
					public void H_UserClient_HttpRequest_Response(
							final H_UserClient_HttpRequest_Result iResult)
					{
						isCommunicatingMap.put(catingTag, false);

						if (iResultHandler == null)
							return;

						Runnable runObject = new Runnable()
						{
							public void run()
							{
								// TDStockLog.d("TAG",
								// catingTag+"=>Thread: "+Thread.interrupted());
								try
								{
									if (iCls != null
											&& iBmpPage != null)
									{
										if (iResult.contentStores != null
												|| iResult.contentStores
														.size() > 0)
										{
											if (iMapObj)
												iResult.SetDataResultMapObj(BMPArrayConvertToMapObject(
														iResult.contentStores,
														iCls,
														iBmpPage));
											else
												iResult.SetDataResultListObj(BMPArrayConvertToListObject(
														iResult.contentStores,
														iCls,
														iBmpPage));
										}
									}

									iResultHandler
											.H_UserClient_HttpRequest_Response(iResult);
								}
								catch (Exception ex)
								{
									TDStockLog.d(
											LOG_TAG,
											"SendHttpRequest=>"
													+ catingTag
													+ "=>Exception: "
													+ ex.toString());
									ex.printStackTrace();
								}
							}
						};
						msgHandler.post(runObject);
					}
				});

		if (debugMode)
			TDStockLog.i(LOG_TAG, "SendHttpRequest=>" + catingTag + "=>"
					+ isCommunicatingMap.get(catingTag) + ",status="
					+ statusCode);

		if (statusCode != H_CODE.OK)
			isCommunicatingMap.put(catingTag, false);

		return statusCode;
	}

	/**
	 * 将 String[] 的 List 转换为 Map Object
	 * 
	 * @param arrList
	 * @param cls
	 * @param bmpPage
	 * @return
	 * @throws IllegalAccessException
	 * @throws InstantiationException
	 */
	static private Map<String, BMPEntityBase> BMPArrayConvertToMapObject(
			List<String[]> arrList, Class<?> cls, BMPPage bmpPage)
			throws IllegalAccessException, InstantiationException
	{
		Map<String, BMPEntityBase> objList = new HashMap<String, BMPEntityBase>();

		for (String[] array : arrList)
		{
			BMPEntityBase instance = (BMPEntityBase) cls.newInstance();

			for (int index = 0; index < array.length; index++)
			{
				try
				{
					String value = array[index];
					if (BMPPage.CURRENT == bmpPage)
					{
						instance.SetValueByFIELDS(index, value);
					}
					else if (BMPPage.STOCK == bmpPage)
					{
						instance.SetValueByFIELDS_STOCK(index, value);
					}
					else if (BMPPage.MONITOR == bmpPage)
					{
						instance.SetValueByFIELDS_MONITOR(index, value);
					}
					else if (BMPPage.COP == bmpPage)
					{
						instance.SetValueByFIELDS_COP(index, value);
					}
					else if (BMPPage.TOP20_NET == bmpPage)
					{
						instance.SetValueByFIELDS_NET(index, value);
					}
					else if (BMPPage.TOP20_TURNOVER == bmpPage)
					{
						instance.SetValueByFIELDS_TURNOVER(index, value);
					}
				}
				catch (Exception e)
				{
					e.printStackTrace();
				}
			}
			objList.put(instance.GetKey(), instance);
		}
		return objList;
	}

	/**
	 * 将 String[] 的 List 转换为 List Object
	 * 
	 * @param arrList
	 * @param cls
	 * @param bmpPage
	 * @return
	 * @throws IllegalAccessException
	 * @throws InstantiationException
	 */
	static private List<BMPEntityBase> BMPArrayConvertToListObject(
			List<String[]> arrList, Class<?> cls, BMPPage bmpPage)
			throws IllegalAccessException, InstantiationException
	{
		List<BMPEntityBase> objList = new ArrayList<BMPEntityBase>();

		for (String[] array : arrList)
		{
			BMPEntityBase instance = (BMPEntityBase) cls.newInstance();

			for (int index = 0; index < array.length; index++)
			{
				try
				{
					String value = array[index];
					if (BMPPage.CURRENT == bmpPage)
					{
						instance.SetValueByFIELDS(index, value);
					}
					else if (BMPPage.STOCK == bmpPage)
					{
						instance.SetValueByFIELDS_STOCK(index, value);
					}
					else if (BMPPage.MONITOR == bmpPage)
					{
						instance.SetValueByFIELDS_MONITOR(index, value);
					}
					else if (BMPPage.COP == bmpPage)
					{
						instance.SetValueByFIELDS_COP(index, value);
					}
					else if (BMPPage.TOP20_NET == bmpPage)
					{
						instance.SetValueByFIELDS_NET(index, value);
					}
					else if (BMPPage.TOP20_TURNOVER == bmpPage)
					{
						instance.SetValueByFIELDS_TURNOVER(index, value);
					}
				}
				catch (Exception e)
				{
					e.printStackTrace();
				}
			}
			objList.add(instance);
		}
		return objList;
	}

	/**
	 * 用戶登錄
	 * 
	 * @param iUserName
	 * @param iPassword
	 * @param iAuthRequest
	 * @return
	 */
	static public H_CODE SendFrameworkILoginAuthRequest(String iUserName,
			String iPassword,
			final ILS_UserClient_Authentication_Report iAuthRequest)
	{
		return SendFrameworkLogon(iUserName, iPassword, null, iAuthRequest);
	}

	/**
	 * 試用登錄
	 * 
	 * @param iActivateCode
	 * @param iAuthRequest
	 * @return
	 */
	static public H_CODE SendFrameworkTrialAuthRequest(String iActivateCode,
			final ILS_UserClient_Authentication_Report iAuthRequest)
	{
		return SendFrameworkLogon(null, null, iActivateCode, iAuthRequest);
	}

	static private H_CODE SendFrameworkLogon(String iUserName,
			String iPassword, String iActivateCode,
			final ILS_UserClient_Authentication_Report iAuthRequest)
	{
		if (iContext == null)
			return H_CODE.UNKNOW;

		H_CODE statusCode;
		boolean iSuccessSend = true;

		if (iActivateCode != null)
			iSuccessSend = ((ITDLApplication) iContext
					.getApplicationContext()).LS_RequestFreeTrialActivate(
					iActivateCode, iAuthRequest);
		else
			iSuccessSend = ((ITDLApplication) iContext
					.getApplicationContext()).LSClient_Logon(iUserName,
					iPassword, iAuthRequest);

		if (iSuccessSend)
			statusCode = H_CODE.OK;
		else
			statusCode = H_CODE.UNKNOW;
		return statusCode;
	}

	/**
	 * Retry framework logon request, get sessionKey.
	 * 
	 * @param iAuthRequest
	 *            callback: ILS_UserClient_Authentication_Report
	 */
	static public H_CODE SendFrameworkReLogonRequest(
			final ILS_UserClient_Authentication_Report iAuthRequest)
	{
		if (iContext == null)
			return H_CODE.UNKNOW;

		H_CODE statusCode;
		boolean iSuccessSend = true;

		if (IsFreeTrial())
			iSuccessSend = ((ITDLApplication) iContext
					.getApplicationContext()).LS_RequestFreeTrialActivate(
					GetActivateCode(), iAuthRequest);
		else
			iSuccessSend = ((ITDLApplication) iContext
					.getApplicationContext()).LSClient_Logon(
					GetUserName(), GetPassword(), iAuthRequest);

		if (iSuccessSend)
			statusCode = H_CODE.OK;
		else
			statusCode = H_CODE.UNKNOW;
		return statusCode;
	}

	// static final private String URL_ILOGIN_AUTH_TOSTRING =
	// "http://#FromServer#/RealtimeStock/ilogin.do?login_name=#UserName#&password=#Password#"
	// +
	// "&view=iphone&lang=chi&location=hk&device_id=#DeviceID#&type=" +
	// CommonDefn.DEVICE_TYPE + "&version=";
	// static final private String URL_TRIALFREE_AUTH_TOSTRING =
	// "http://#FromServer#/RealtimeStock/ilogin.do?location=trial&device_id=#DeviceID#"
	// +
	// "&dvc_type=" + CommonDefn.DEVICE_TYPE +
	// "&view=android&act_code=#ActivateCode#";// + URLEncoder.encode(actCode);

	static public H_CODE SendReLogonRequest(Context iContext,
			final IH_ILoginAuthRequest_Report iResultHandler)
	{
		H_CODE statusCode;
		H_ILoginAuthRequest requestCmd;
		String urlToString;

		if (debugMode)
			TDStockLog.i(LOG_TAG, "isLSLogonCommunicating:"
					+ isLSLogonCommunicating);

		// Use to block the multiple communication
		if (isLSLogonCommunicating)
			return H_CODE.SYSTEM_BUSY;

		isLSLogonCommunicating = true;

		urlToString = LS_ClientParamMemory.Get_AuthenticationURL(iContext,
				GetUserName(), GetPassword());

		if (IsFreeTrial())
			urlToString = LS_ClientParamMemory
					.Get_RequestFreeTrialActivateURL(iContext,
							GetActivateCode());

		if (debugMode)
			TDStockLog.i(LOG_TAG, "ilogin=>UrlToString: " + urlToString);

		requestCmd = new H_ILoginAuthRequest(iContext);
		statusCode = requestCmd.SubmitRequest(urlToString,
				new IH_ILoginAuthRequest_Report()
				{
					@Override
					public void H_ILoginAuthRequest_Response(
							final H_ILoginAuthRequest_Result iResult)
					{
						isLSLogonCommunicating = false;

						if (iResultHandler == null)
							return;

						Runnable runObject = new Runnable()
						{
							public void run()
							{
								try
								{
									iResultHandler
											.H_ILoginAuthRequest_Response(iResult);
								}
								catch (Exception ex)
								{
									TDStockLog.e(
											LOG_TAG,
											"SendILoginAuthRequest=>Exception: "
													+ ex.toString());
									ex.printStackTrace();
								}
							}
						};
						msgHandler.post(runObject);
					}
				});

		TDStockLog.d(LOG_TAG, "SendILoginAuthRequest>>"
				+ isLSLogonCommunicating + ",status=" + statusCode);

		if (statusCode != H_CODE.OK)
			isLSLogonCommunicating = false;

		return statusCode;
	}

	/**
	 * 用戶登錄
	 * 
	 * @param iContext
	 * @param iUserName
	 * @param iPassword
	 * @param iResultHandler
	 * @return
	 */
	static public H_CODE SendILoginAuthRequest(Context iContext,
			String iUserName, String iPassword,
			final IH_ILoginAuthRequest_Report iResultHandler)
	{
		return ILoginAuth(iContext, iUserName, iPassword, null,
				iResultHandler);
	}

	/**
	 * 試用登錄
	 * 
	 * @param iContext
	 * @param iActivateCode
	 * @param iResultHandler
	 * @return
	 */
	static public H_CODE SendTrialAuthRequest(Context iContext,
			String iActivateCode,
			final IH_ILoginAuthRequest_Report iResultHandler)
	{
		return ILoginAuth(iContext, null, null, iActivateCode, iResultHandler);
	}

	static private H_CODE ILoginAuth(Context iContext, String iUserName,
			String iPassword, String iActivateCode,
			final IH_ILoginAuthRequest_Report iResultHandler)
	{
		H_CODE statusCode;
		H_ILoginAuthRequest requestCmd;
		String urlToString;

		if (debugMode)
			TDStockLog.i(LOG_TAG, "isLSLogonCommunicating:"
					+ isLSLogonCommunicating);

		if (isLSLogonCommunicating)
			return H_CODE.SYSTEM_BUSY;

		isLSLogonCommunicating = true;

		if (iActivateCode != null)
			urlToString = LS_ClientParamMemory
					.Get_RequestFreeTrialActivateURL(iContext,
							iActivateCode);
		else
			urlToString = LS_ClientParamMemory.Get_AuthenticationURL(
					iContext, iUserName, iPassword);

		if (debugMode)
			TDStockLog.i(LOG_TAG, "ilogin=>UrlToString: " + urlToString);

		requestCmd = new H_ILoginAuthRequest(iContext);
		statusCode = requestCmd.SubmitRequest(urlToString,
				new IH_ILoginAuthRequest_Report()
				{
					@Override
					public void H_ILoginAuthRequest_Response(
							final H_ILoginAuthRequest_Result iResult)
					{
						isLSLogonCommunicating = false;

						if (iResultHandler == null)
							return;

						Runnable runObject = new Runnable()
						{
							public void run()
							{
								try
								{
									iResultHandler
											.H_ILoginAuthRequest_Response(iResult);
								}
								catch (Exception ex)
								{
									TDStockLog.e(
											LOG_TAG,
											"SendILoginAuthRequest=>Exception: "
													+ ex.toString());
									ex.printStackTrace();
								}
							}
						};
						msgHandler.post(runObject);
					}
				});

		if (statusCode != H_CODE.OK)
			isLSLogonCommunicating = false;

		return statusCode;
	}

	/*-------------------Betting > Mark 6---------------------*/

	static final private String	URL_BETTING_MARK6_INFO_TOSTRING	= "http://#FromServer#/iphone/mark6/mk6Info4Bet.do?account=#AccountNumber#&token=#TokenKey#";

	static public H_CODE SendMK6InfoBetRequest(Context iContext,
			IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getSimpleName();

		String iRootName = "Mark6";
		String iEntityRootName = "Mk6Info,Mk6Snowball";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = { "DrawIdYear", "DrawIdDrawNo", "DrawDate",
				"CWeekDay", "CloseTime", "Jackpot", "Est1stPrizeFund",
				"SnowballCname", "DrawId", "SnowballSname", "Snowball" };

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequest(iContext, catingTag,
				URL_BETTING_MARK6_INFO_TOSTRING, iResultHandler, iSeqID);

		return statusCode;
	}

	//static final private String	URL_BOOKMARK_SET	= "http://quotedev2.telecomdigital.cc/notification/setBookmark.do?account=#AccountNumber#&token=#TokenKey#&item=%s&type=%s&view=gphone&version=1.4.2.3.0.1";
	static final private String	URL_BOOKMARK_SET	= "http://#FromServer#/notification/setBookmark.do?account=#AccountNumber#&token=#TokenKey#&item=%s&type=%s&view=gphone&version=1.4.2.3.0.1";
	static public H_CODE SaveBookMark(Context iContext, StringBuffer bookMarkItem,
			StringBuffer bookMarkType,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName()
				+ "_SaveBookMark";

		String iRootName = "Bookmark";
		String iEntityRootName = null;
		String[] iHeaderFieldNames = { "Status" };
		String[] iFieldNames = { };

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequest(iContext, catingTag, String.format(
				URL_BOOKMARK_SET.replace("#FromServer#", "quotedev2.telecomdigital.cc"), bookMarkItem == null ? "" : bookMarkItem,
				bookMarkType == null ? "" : bookMarkType), iResultHandler,
				iSeqID);

		return statusCode;
	}
	
	//static public String		BOOKMARK_GET_URL	= "http://quotedev2.telecomdigital.cc/notification/getBookmark.do?account=#AccountNumber#&token=#TokenKey#&view=gphone&version=1.4.2.3.0.1";
	static public String	BOOKMARK_GET_URL	= "http://#FromServer#/notification/getBookmark.do?account=#AccountNumber#&token=#TokenKey#&view=gphone&version=1.4.2.3.0.1";

	static public H_CODE GetBookMark(Context iContext,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName()
				+ "_GetBookMark";
		TDStockLog.d(LOG_TAG, HttpAppInfo.class.getSimpleName()
				+ "------------->GetBookMark");
		String iRootName = "Bookmark";
		String iEntityRootName = "Record";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = { "Item", "TypeId" };

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequest(iContext, catingTag, BOOKMARK_GET_URL,
				iResultHandler, iSeqID);

		return statusCode;
	}

	static public String	NOTIFICATION_SWITCH_URL	= "http://#FromServer#/notification/getAccountProfile.do?nsid=&account=#AccountNumber#&token=#TokenKey#";

	static public H_CODE GetNotificationSwitch(Context iContext,
			final IH_UserClient_HttpRequest_Report iResultHandler,
			final String... iSeqID)
	{
		final String catingTag = iContext.getClass().getName()
				+ "_GetNotificationSwitch";
		TDStockLog.d(LOG_TAG, HttpAppInfo.class.getSimpleName()
				+ "------------->GetBookMark");
		String iRootName = "AccountProfile";
		String iEntityRootName = "Record";
		String[] iHeaderFieldNames = null;
		String[] iFieldNames = { "EnableNotification", "TimeFiltering",
				"StartTime", "EndTime" };

		SetElementNameInformation(iRootName, iHeaderFieldNames,
				iEntityRootName, iFieldNames);

		H_CODE statusCode;
		statusCode = SendHttpRequest(iContext, catingTag,
				NOTIFICATION_SWITCH_URL, iResultHandler, iSeqID);

		return statusCode;
	}
}
